home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 August: Tool Chest / Dev.CD Aug 94.toast / New System Software Extensions / OpenDoc A6 / OpenDoc Parts Framework / OPF / Found / FWExcLib / Sources / FWTryBlo.cpp < prev    next >
Encoding:
Text File  |  1994-04-21  |  3.1 KB  |  97 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWTryBlo.cpp
  4. //    Release Version:    $ 1.0d1 $
  5. //
  6. //    Creation Date:        3/28/94
  7. //
  8. //    Copyright:    © 1994 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #ifndef   FWTRYBLO_H
  13. #include "FWTryBlo.h"
  14. #endif
  15.  
  16. #ifndef   FWEXCRUN_H
  17. #include "FWExcRun.h"
  18. #endif
  19.  
  20. #ifndef   FWDELSTA_H
  21. #include "FWDelSta.h"
  22. #endif
  23.  
  24. #ifdef FW_BUILD_MAC
  25. #pragma segment BEL
  26. #endif
  27.  
  28. //========================================================================================
  29. // CLASS _FW_CTryBlockContext
  30. //========================================================================================
  31.  
  32. #pragma trace off
  33.  
  34. //----------------------------------------------------------------------------------------
  35. // _FW_CTryBlockContext::~_FW_CTryBlockContext
  36. //----------------------------------------------------------------------------------------
  37. _FW_CTryBlockContext::~_FW_CTryBlockContext()
  38. {
  39. #ifdef FW_DEBUG
  40.     CheckClassInvariants(fGlobals);
  41.     fGlobals.gContextDepth--;
  42.     FW_PRIV_ASSERT(fAutomaticsInMyScope == 0);
  43. #endif
  44.         
  45.     _FW_CTryBlockContext *priorContext = MakeCurrent(fGlobals, fPriorContext);
  46.     FW_PRIV_ASSERT(priorContext == this);
  47. }
  48.  
  49. //----------------------------------------------------------------------------------------
  50. // _FW_CTryBlockContext::_FW_CTryBlockContext
  51. //----------------------------------------------------------------------------------------
  52. _FW_CTryBlockContext::_FW_CTryBlockContext(FW_SPrivExceptionGlobals& globals, jmp_buf buffer) :
  53.     fGlobals(globals),
  54.     fJumpBuffer((jmp_buf *) buffer)
  55. {
  56.     fPriorContext = MakeCurrent(fGlobals, this);
  57.     fDeleteStackLevel = _FW_CDeleteStack::RelativeTopOfStack(fGlobals);
  58.  
  59. #ifdef FW_DEBUG
  60.     fGlobals.gContextDepth++;
  61.     fAutomaticsInMyScope = 0;
  62.     CheckClassInvariants(fGlobals);
  63. #endif
  64. }
  65.  
  66. //----------------------------------------------------------------------------------------
  67. // _FW_CTryBlockContext::MakeCurrent
  68. //----------------------------------------------------------------------------------------
  69. class _FW_CTryBlockContext *_FW_CTryBlockContext::MakeCurrent(
  70.                                             FW_SPrivExceptionGlobals& globals,
  71.                                             _FW_CTryBlockContext *context)
  72. {
  73.     _FW_CTryBlockContext *tmpContext = globals.gCurrentContext;
  74.     globals.gCurrentContext = context;
  75.     return tmpContext;
  76. }
  77.  
  78. #ifdef FW_DEBUG
  79. //----------------------------------------------------------------------------------------
  80. // _FW_CTryBlockContext::CheckClassInvariants
  81. //
  82. //        Should only be called on current context.
  83. //----------------------------------------------------------------------------------------
  84. void _FW_CTryBlockContext::CheckClassInvariants(FW_SPrivExceptionGlobals& globals)
  85. {
  86.     // Ensure class invariants
  87.     FW_PRIV_ASSERT(&globals == &fGlobals);
  88.     FW_PRIV_ASSERT(globals.gContextDepth>=1);
  89.     FW_PRIV_ASSERT(globals.gContextDepth>1 || fPriorContext==NULL);
  90.     FW_PRIV_ASSERT(globals.gContextDepth==1 || fPriorContext!=NULL);
  91.     FW_PRIV_ASSERT(fAutomaticsInMyScope >= 0);
  92.     FW_PRIV_ASSERT(fDeleteStackLevel >= 0);
  93.     FW_PRIV_ASSERT(globals.gCurrentContext == this);
  94. }
  95. #endif
  96.  
  97.